import React from 'react'
import Link from 'next/link'
import Layout from '@/components/layout'
import Posts from '@/components/posts'
import { getLatestPosts } from '@/lib/apis'
import PostType from '@/types/post'

import type { GetStaticProps, NextPage } from 'next'
export type IndexProps = {
  latestPosts: PostType[]
}

export const getStaticProps: GetStaticProps = async () => {
  const latestPosts = getLatestPosts()
  return {
    props: {
      latestPosts,
    },
    revalidate: 1,
  }
}

const Home: NextPage<IndexProps> = ({ latestPosts }) => {
  return (
    <Layout>
      <Posts posts={latestPosts} />
      <Link href="/posts">
        <a className="block text-center mx-auto mt-8 text-2xl text-green-500">
          所有文章
        </a>
      </Link>
    </Layout>
  )
}

export default Home
